Repository navigation
fix(ios): Don't animate views created by a mount inside a UIKit animation block - #60222
maxlapides wants to merge 1 commit into
Conversation
…tion block A transaction can be mounted synchronously from inside a UIKit animation block, for example when a component sends an unstable_Immediate state update from one. That mount includes any React commit that was pushed but not yet mounted, and the views it creates picked up the surrounding animation: they grew in from a zero frame, or moved from a recycled view's last frame. Views created by the transaction are now configured inside performWithoutAnimation. Existing views keep animating along.
|
Hi @maxlapides! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary:
Fixes #60221.
On iOS, a mount can run synchronously inside a UIKit animation block. The common case is a component that sends an
unstable_Immediatestate update from inside+[UIView animateWithDuration:animations:]or-[UISheetPresentationController animateChanges:], so that its children's new layout animates along with a native change. That mount pulls the latest revision of the surface, so it also includes any React commit that was pushed but not mounted yet. The views it creates are configured inside the animation block and inherit the animation: new views grow in from a zero frame (their parent's top-left corner), and recycled views move from their last frame. react-native-true-sheet hits this when a sheet changes detents (lodev09/react-native-true-sheet#1038).With this change, a view's initial configuration no longer inherits the surrounding animation. When
RCTPerformMountInstructionsruns inside an animation block (+[UIView inheritedAnimationDuration] > 0), it records the tags the transaction creates, and configures those views onInsert(props, event emitter, state, layout metrics andfinalizeUpdates:) inside+[UIView performWithoutAnimation:].What stays the same:
Remove+InsertwithoutCreate), still animate with the surrounding block, so existing content keeps animating along with the native change.LayoutAnimationand other surfaces' state updates are unaffected.Known limits:
UIViewanimation from its firstupdateProps:orfinalizeUpdates:while mounted inside an outer animation block, that animation is now skipped and the end state applies immediately. Before, it inherited the outer block's duration and curve.layoutSubviews, still inherits the animation. Core components set their subview frames inupdateLayoutMetrics:, exceptRCTParagraphComponentView, which positions its text view inlayoutSubviews. In the react-native-true-sheet case below, text inside new views also appeared in place.Changelog:
[IOS] [FIXED] - Views created by a mount that runs inside a UIKit animation block, for example from an immediate state update, no longer animate in from a zero frame
Test Plan:
Reproducer: https://github.com/maxlapides/rn-mount-animation-repro, from the react-native-community template on React Native 0.88.1, whose
RCTMountingManager.mmis identical tomainbefore this change. All runs used an iPhone 17 Pro simulator on iOS 27.2 with Xcode 27.2, Debug builds.pod install), and from source (RCT_USE_PREBUILT_RNCORE=0 pod install) with and without this patch applied tonode_modules/react-native(fix/RCTMountingManager.patchin the reproducer).mainwithout a workaround). Its Resize Race sheet changes detents while a grid commit is pending. With stock React Native, the grid grew in from the corner on 3 of 3 expands. With the patch, it appeared in place on 5 of 5, and the existing sheet content still moved with the sheet. Text labels added to the tiles also appeared in place.clang-format21 with the repository's.clang-formatreports no changes.Not run: RNTester, physical devices, other iOS versions. There are no unit tests for
RCTMountingManager. Android doesn't use this code.Reproducer, first tap, frames 0.15 s apart (top: before, bottom: after):
react-native-true-sheet Resize Race, first expand, frames 67 ms apart (top: stock React Native, bottom: this patch):